<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/3/25
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>删除用户</title>
    <%--<meta http-equiv="refresh" content="0.5;URL=/userList.jsp">--%>
    <style type="text/css">
        button a {
            text-decoration: none;
        }
    </style>
    <script>
        function goto(){
            window.location.href="/userList.jsp";
        }
    </script>
</head>
<body>
<%

    //JDBC 3+1
    Connection connection = null;
//    Statement statement = null;
//    ResultSet resultSet = null;

    String sql = "delete from t_users where id=?";

    Class.forName("com.mysql.jdbc.Driver");

    connection = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?characterEncoding=utf-8&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC",
            "root",
            "123456"
    );

    //预编译SQL，减少sql执行
    PreparedStatement ptmt = connection.prepareStatement(sql);

    //传参
    ptmt.setInt(1, Integer.parseInt(request.getParameter("id")));

    //执行
    ptmt.execute();


    // 重定向到新地址
    String site = new String("/userList.jsp");
    response.setStatus(response.SC_MOVED_TEMPORARILY);
    response.setHeader("Location", site);
%>

</body>
</html>
